package com.lwl.service.impl.mht;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lwl.entity.MyPage;
import com.lwl.entity.mht.TMhtPlane;
import com.lwl.service.mht.TMhtPlaneService;
import com.lwl.dao.mht.TMhtPlaneMapper;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * (TMhtPlane)表服务实现类
 *
 * @author Lei
 * @since 2022-10-27 16:57:40
 */
@Service
public class TMhtPlaneServiceImpl implements TMhtPlaneService {
   @Autowired
   private TMhtPlaneMapper tMhtPlaneDao;

   @Override
   public PageInfo queryAll(MyPage myPage, TMhtPlane tMhtPlane) {
      PageHelper.startPage(myPage.getPage(), myPage.getLimit());
      List<TMhtPlane> tMhtPlaneList = tMhtPlaneDao.selectAllData(tMhtPlane);
      PageInfo pageInfo = new PageInfo(tMhtPlaneList);
      return pageInfo;
   }

   @Override
   public boolean selectCode(TMhtPlane tMhtPlane) {
      List<TMhtPlane> select = tMhtPlaneDao.select(tMhtPlane);
      return select.size()==0;
   }

   @Override
   public boolean insertPlane(TMhtPlane tMhtPlane) {
      int insert = -1;
      if (tMhtPlane.getId()==null){
         insert = tMhtPlaneDao.insert(tMhtPlane);
      }else {
         tMhtPlane.setUpdatetime(new Date());
         insert = tMhtPlaneDao.updateByPrimaryKeySelective(tMhtPlane);
      }
      return insert>0?true:false;
   }

   //      根据名字查询是否有重名的计划
   @Override
   public boolean queryByName(String planname) {
      List<TMhtPlane> tMhtPlane1 = tMhtPlaneDao.queryOne(planname);
      return tMhtPlane1.size()==0?true:false;
   }

   //   根据邀请码获取计划信息，验证是否在做题时间
   @Override
   public TMhtPlane getByCode(TMhtPlane tMhtPlane) {
      TMhtPlane tMhtPlane1 = tMhtPlaneDao.selectOne(tMhtPlane);
      return tMhtPlane1;
   }

   @Override
   public boolean checkPlanId(String planid) {
      TMhtPlane tMhtPlane1 = tMhtPlaneDao.selectByPrimaryKey(planid);
      System.out.println("查到的计划是tMhtPlane = " + tMhtPlane1);
      if (tMhtPlane1==null){
         return false;
      }else {
         return true;
      }
   }
}
